import redis
from connect_to_redis import BaseRedisConnection


class TestSet(BaseRedisConnection):
    # sadd/srem:添加/删除成员
    # sismember：判断是否为set的一个成员
    # smembers:返回该集合的所有成员
    # sdiff：返回一个集合与其他集合的差异
    # sinter：返回几个集合的交集
    # sunion：返回几个集合的并集

    def test_sadd(self):
        # sadd/srem:添加/删除成员
        result = self.conn.sadd('zoo1','Dog','Cat')
        print(result)
        animals = ['Monkey','Panda','Dog']
        result = self.conn.sadd('zoo1',*animals)
        print(result)
        members = self.conn.smembers('zoo1')
        print(members)

    def test_srem(self):
        # sadd/srem:添加/删除成员
        result = self.conn.srem('zoo1','Dog')
        print(result)
        members = self.conn.smembers('zoo1')
        print(members)


    def course_analysis(self):
        # 课程分析
        # 1.自然科学
        science_stu_list = ['Stu003','Stu022','Stu021','Stu012','Stu014']
        self.conn.sadd('science',*science_stu_list)
        # 2.大学英语
        english_stu_list = ['Stu001','Stu021','Stu011','Stu012','Stu014']
        self.conn.sadd('english', *english_stu_list)

        result = self.conn.sinter("science",'english')
        print(result)




def main():
    str_obj = TestSet()
    # str_obj.test_sadd()
    # str_obj.test_srem()
    str_obj.course_analysis()




if __name__ == '__main__':
    main()